package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.Lookup;
import com.xjgzinfo.usdp.repository.LookupRepository;
import com.xjgzinfo.usdp.service.LookupService;
import com.xjgzinfo.usdp.service.dto.LookupDTO;
import com.xjgzinfo.usdp.service.mapper.LookupMapper;
import com.xjgzinfo.usdp.service.dto.LookupCriteria;
import com.xjgzinfo.usdp.service.LookupQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link LookupResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class LookupResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_CODE = "AAAAAAAAAA";
    private static final String UPDATED_CODE = "BBBBBBBBBB";

    private static final Integer DEFAULT_ORDER_SEQ = 1;
    private static final Integer UPDATED_ORDER_SEQ = 2;
    private static final Integer SMALLER_ORDER_SEQ = 1 - 1;

    private static final String DEFAULT_GROUP = "AAAAAAAAAA";
    private static final String UPDATED_GROUP = "BBBBBBBBBB";

    private static final String DEFAULT_MEANING = "AAAAAAAAAA";
    private static final String UPDATED_MEANING = "BBBBBBBBBB";

    private static final String DEFAULT_VALUE = "AAAAAAAAAA";
    private static final String UPDATED_VALUE = "BBBBBBBBBB";

    private static final String DEFAULT_COMMENT = "AAAAAAAAAA";
    private static final String UPDATED_COMMENT = "BBBBBBBBBB";

    private static final Boolean DEFAULT_MULTI_SELECT = false;
    private static final Boolean UPDATED_MULTI_SELECT = true;

    @Autowired
    private LookupRepository lookupRepository;

    @Autowired
    private LookupMapper lookupMapper;

    @Autowired
    private LookupService lookupService;

    @Autowired
    private LookupQueryService lookupQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restLookupMockMvc;

    private Lookup lookup;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Lookup createEntity(EntityManager em) {
        Lookup lookup = new Lookup()
            .name(DEFAULT_NAME)
            .code(DEFAULT_CODE)
            .orderSeq(DEFAULT_ORDER_SEQ)
            .group(DEFAULT_GROUP)
            .meaning(DEFAULT_MEANING)
            .value(DEFAULT_VALUE)
            .comment(DEFAULT_COMMENT)
            .multiSelect(DEFAULT_MULTI_SELECT);
        return lookup;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Lookup createUpdatedEntity(EntityManager em) {
        Lookup lookup = new Lookup()
            .name(UPDATED_NAME)
            .code(UPDATED_CODE)
            .orderSeq(UPDATED_ORDER_SEQ)
            .group(UPDATED_GROUP)
            .meaning(UPDATED_MEANING)
            .value(UPDATED_VALUE)
            .comment(UPDATED_COMMENT)
            .multiSelect(UPDATED_MULTI_SELECT);
        return lookup;
    }

    @BeforeEach
    public void initTest() {
        lookup = createEntity(em);
    }

    @Test
    @Transactional
    public void createLookup() throws Exception {
        int databaseSizeBeforeCreate = lookupRepository.findAll().size();
        // Create the Lookup
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);
        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isCreated());

        // Validate the Lookup in the database
        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeCreate + 1);
        Lookup testLookup = lookupList.get(lookupList.size() - 1);
        assertThat(testLookup.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testLookup.getCode()).isEqualTo(DEFAULT_CODE);
        assertThat(testLookup.getOrderSeq()).isEqualTo(DEFAULT_ORDER_SEQ);
        assertThat(testLookup.getGroup()).isEqualTo(DEFAULT_GROUP);
        assertThat(testLookup.getMeaning()).isEqualTo(DEFAULT_MEANING);
        assertThat(testLookup.getValue()).isEqualTo(DEFAULT_VALUE);
        assertThat(testLookup.getComment()).isEqualTo(DEFAULT_COMMENT);
        assertThat(testLookup.isMultiSelect()).isEqualTo(DEFAULT_MULTI_SELECT);
    }

    @Test
    @Transactional
    public void createLookupWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = lookupRepository.findAll().size();

        // Create the Lookup with an existing ID
        lookup.setId(1L);
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);

        // An entity with an existing ID cannot be created, so this API call must fail
        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Lookup in the database
        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setName(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkCodeIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setCode(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkOrderSeqIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setOrderSeq(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkGroupIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setGroup(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkMeaningIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setMeaning(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkValueIsRequired() throws Exception {
        int databaseSizeBeforeTest = lookupRepository.findAll().size();
        // set the field null
        lookup.setValue(null);

        // Create the Lookup, which fails.
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);


        restLookupMockMvc.perform(post("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllLookups() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList
        restLookupMockMvc.perform(get("/api/lookups?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(lookup.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].orderSeq").value(hasItem(DEFAULT_ORDER_SEQ)))
            .andExpect(jsonPath("$.[*].group").value(hasItem(DEFAULT_GROUP)))
            .andExpect(jsonPath("$.[*].meaning").value(hasItem(DEFAULT_MEANING)))
            .andExpect(jsonPath("$.[*].value").value(hasItem(DEFAULT_VALUE)))
            .andExpect(jsonPath("$.[*].comment").value(hasItem(DEFAULT_COMMENT)))
            .andExpect(jsonPath("$.[*].multiSelect").value(hasItem(DEFAULT_MULTI_SELECT.booleanValue())));
    }
    
    @Test
    @Transactional
    public void getLookup() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get the lookup
        restLookupMockMvc.perform(get("/api/lookups/{id}", lookup.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(lookup.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.code").value(DEFAULT_CODE))
            .andExpect(jsonPath("$.orderSeq").value(DEFAULT_ORDER_SEQ))
            .andExpect(jsonPath("$.group").value(DEFAULT_GROUP))
            .andExpect(jsonPath("$.meaning").value(DEFAULT_MEANING))
            .andExpect(jsonPath("$.value").value(DEFAULT_VALUE))
            .andExpect(jsonPath("$.comment").value(DEFAULT_COMMENT))
            .andExpect(jsonPath("$.multiSelect").value(DEFAULT_MULTI_SELECT.booleanValue()));
    }


    @Test
    @Transactional
    public void getLookupsByIdFiltering() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        Long id = lookup.getId();

        defaultLookupShouldBeFound("id.equals=" + id);
        defaultLookupShouldNotBeFound("id.notEquals=" + id);

        defaultLookupShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultLookupShouldNotBeFound("id.greaterThan=" + id);

        defaultLookupShouldBeFound("id.lessThanOrEqual=" + id);
        defaultLookupShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllLookupsByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name equals to DEFAULT_NAME
        defaultLookupShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the lookupList where name equals to UPDATED_NAME
        defaultLookupShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllLookupsByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name not equals to DEFAULT_NAME
        defaultLookupShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the lookupList where name not equals to UPDATED_NAME
        defaultLookupShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllLookupsByNameIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name in DEFAULT_NAME or UPDATED_NAME
        defaultLookupShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the lookupList where name equals to UPDATED_NAME
        defaultLookupShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllLookupsByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name is not null
        defaultLookupShouldBeFound("name.specified=true");

        // Get all the lookupList where name is null
        defaultLookupShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByNameContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name contains DEFAULT_NAME
        defaultLookupShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the lookupList where name contains UPDATED_NAME
        defaultLookupShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllLookupsByNameNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where name does not contain DEFAULT_NAME
        defaultLookupShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the lookupList where name does not contain UPDATED_NAME
        defaultLookupShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllLookupsByCodeIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code equals to DEFAULT_CODE
        defaultLookupShouldBeFound("code.equals=" + DEFAULT_CODE);

        // Get all the lookupList where code equals to UPDATED_CODE
        defaultLookupShouldNotBeFound("code.equals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllLookupsByCodeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code not equals to DEFAULT_CODE
        defaultLookupShouldNotBeFound("code.notEquals=" + DEFAULT_CODE);

        // Get all the lookupList where code not equals to UPDATED_CODE
        defaultLookupShouldBeFound("code.notEquals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllLookupsByCodeIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code in DEFAULT_CODE or UPDATED_CODE
        defaultLookupShouldBeFound("code.in=" + DEFAULT_CODE + "," + UPDATED_CODE);

        // Get all the lookupList where code equals to UPDATED_CODE
        defaultLookupShouldNotBeFound("code.in=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllLookupsByCodeIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code is not null
        defaultLookupShouldBeFound("code.specified=true");

        // Get all the lookupList where code is null
        defaultLookupShouldNotBeFound("code.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByCodeContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code contains DEFAULT_CODE
        defaultLookupShouldBeFound("code.contains=" + DEFAULT_CODE);

        // Get all the lookupList where code contains UPDATED_CODE
        defaultLookupShouldNotBeFound("code.contains=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllLookupsByCodeNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where code does not contain DEFAULT_CODE
        defaultLookupShouldNotBeFound("code.doesNotContain=" + DEFAULT_CODE);

        // Get all the lookupList where code does not contain UPDATED_CODE
        defaultLookupShouldBeFound("code.doesNotContain=" + UPDATED_CODE);
    }


    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq equals to DEFAULT_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.equals=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq equals to UPDATED_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.equals=" + UPDATED_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq not equals to DEFAULT_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.notEquals=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq not equals to UPDATED_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.notEquals=" + UPDATED_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq in DEFAULT_ORDER_SEQ or UPDATED_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.in=" + DEFAULT_ORDER_SEQ + "," + UPDATED_ORDER_SEQ);

        // Get all the lookupList where orderSeq equals to UPDATED_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.in=" + UPDATED_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq is not null
        defaultLookupShouldBeFound("orderSeq.specified=true");

        // Get all the lookupList where orderSeq is null
        defaultLookupShouldNotBeFound("orderSeq.specified=false");
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq is greater than or equal to DEFAULT_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.greaterThanOrEqual=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq is greater than or equal to UPDATED_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.greaterThanOrEqual=" + UPDATED_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq is less than or equal to DEFAULT_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.lessThanOrEqual=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq is less than or equal to SMALLER_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.lessThanOrEqual=" + SMALLER_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsLessThanSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq is less than DEFAULT_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.lessThan=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq is less than UPDATED_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.lessThan=" + UPDATED_ORDER_SEQ);
    }

    @Test
    @Transactional
    public void getAllLookupsByOrderSeqIsGreaterThanSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where orderSeq is greater than DEFAULT_ORDER_SEQ
        defaultLookupShouldNotBeFound("orderSeq.greaterThan=" + DEFAULT_ORDER_SEQ);

        // Get all the lookupList where orderSeq is greater than SMALLER_ORDER_SEQ
        defaultLookupShouldBeFound("orderSeq.greaterThan=" + SMALLER_ORDER_SEQ);
    }


    @Test
    @Transactional
    public void getAllLookupsByGroupIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group equals to DEFAULT_GROUP
        defaultLookupShouldBeFound("group.equals=" + DEFAULT_GROUP);

        // Get all the lookupList where group equals to UPDATED_GROUP
        defaultLookupShouldNotBeFound("group.equals=" + UPDATED_GROUP);
    }

    @Test
    @Transactional
    public void getAllLookupsByGroupIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group not equals to DEFAULT_GROUP
        defaultLookupShouldNotBeFound("group.notEquals=" + DEFAULT_GROUP);

        // Get all the lookupList where group not equals to UPDATED_GROUP
        defaultLookupShouldBeFound("group.notEquals=" + UPDATED_GROUP);
    }

    @Test
    @Transactional
    public void getAllLookupsByGroupIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group in DEFAULT_GROUP or UPDATED_GROUP
        defaultLookupShouldBeFound("group.in=" + DEFAULT_GROUP + "," + UPDATED_GROUP);

        // Get all the lookupList where group equals to UPDATED_GROUP
        defaultLookupShouldNotBeFound("group.in=" + UPDATED_GROUP);
    }

    @Test
    @Transactional
    public void getAllLookupsByGroupIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group is not null
        defaultLookupShouldBeFound("group.specified=true");

        // Get all the lookupList where group is null
        defaultLookupShouldNotBeFound("group.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByGroupContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group contains DEFAULT_GROUP
        defaultLookupShouldBeFound("group.contains=" + DEFAULT_GROUP);

        // Get all the lookupList where group contains UPDATED_GROUP
        defaultLookupShouldNotBeFound("group.contains=" + UPDATED_GROUP);
    }

    @Test
    @Transactional
    public void getAllLookupsByGroupNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where group does not contain DEFAULT_GROUP
        defaultLookupShouldNotBeFound("group.doesNotContain=" + DEFAULT_GROUP);

        // Get all the lookupList where group does not contain UPDATED_GROUP
        defaultLookupShouldBeFound("group.doesNotContain=" + UPDATED_GROUP);
    }


    @Test
    @Transactional
    public void getAllLookupsByMeaningIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning equals to DEFAULT_MEANING
        defaultLookupShouldBeFound("meaning.equals=" + DEFAULT_MEANING);

        // Get all the lookupList where meaning equals to UPDATED_MEANING
        defaultLookupShouldNotBeFound("meaning.equals=" + UPDATED_MEANING);
    }

    @Test
    @Transactional
    public void getAllLookupsByMeaningIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning not equals to DEFAULT_MEANING
        defaultLookupShouldNotBeFound("meaning.notEquals=" + DEFAULT_MEANING);

        // Get all the lookupList where meaning not equals to UPDATED_MEANING
        defaultLookupShouldBeFound("meaning.notEquals=" + UPDATED_MEANING);
    }

    @Test
    @Transactional
    public void getAllLookupsByMeaningIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning in DEFAULT_MEANING or UPDATED_MEANING
        defaultLookupShouldBeFound("meaning.in=" + DEFAULT_MEANING + "," + UPDATED_MEANING);

        // Get all the lookupList where meaning equals to UPDATED_MEANING
        defaultLookupShouldNotBeFound("meaning.in=" + UPDATED_MEANING);
    }

    @Test
    @Transactional
    public void getAllLookupsByMeaningIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning is not null
        defaultLookupShouldBeFound("meaning.specified=true");

        // Get all the lookupList where meaning is null
        defaultLookupShouldNotBeFound("meaning.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByMeaningContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning contains DEFAULT_MEANING
        defaultLookupShouldBeFound("meaning.contains=" + DEFAULT_MEANING);

        // Get all the lookupList where meaning contains UPDATED_MEANING
        defaultLookupShouldNotBeFound("meaning.contains=" + UPDATED_MEANING);
    }

    @Test
    @Transactional
    public void getAllLookupsByMeaningNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where meaning does not contain DEFAULT_MEANING
        defaultLookupShouldNotBeFound("meaning.doesNotContain=" + DEFAULT_MEANING);

        // Get all the lookupList where meaning does not contain UPDATED_MEANING
        defaultLookupShouldBeFound("meaning.doesNotContain=" + UPDATED_MEANING);
    }


    @Test
    @Transactional
    public void getAllLookupsByValueIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value equals to DEFAULT_VALUE
        defaultLookupShouldBeFound("value.equals=" + DEFAULT_VALUE);

        // Get all the lookupList where value equals to UPDATED_VALUE
        defaultLookupShouldNotBeFound("value.equals=" + UPDATED_VALUE);
    }

    @Test
    @Transactional
    public void getAllLookupsByValueIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value not equals to DEFAULT_VALUE
        defaultLookupShouldNotBeFound("value.notEquals=" + DEFAULT_VALUE);

        // Get all the lookupList where value not equals to UPDATED_VALUE
        defaultLookupShouldBeFound("value.notEquals=" + UPDATED_VALUE);
    }

    @Test
    @Transactional
    public void getAllLookupsByValueIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value in DEFAULT_VALUE or UPDATED_VALUE
        defaultLookupShouldBeFound("value.in=" + DEFAULT_VALUE + "," + UPDATED_VALUE);

        // Get all the lookupList where value equals to UPDATED_VALUE
        defaultLookupShouldNotBeFound("value.in=" + UPDATED_VALUE);
    }

    @Test
    @Transactional
    public void getAllLookupsByValueIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value is not null
        defaultLookupShouldBeFound("value.specified=true");

        // Get all the lookupList where value is null
        defaultLookupShouldNotBeFound("value.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByValueContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value contains DEFAULT_VALUE
        defaultLookupShouldBeFound("value.contains=" + DEFAULT_VALUE);

        // Get all the lookupList where value contains UPDATED_VALUE
        defaultLookupShouldNotBeFound("value.contains=" + UPDATED_VALUE);
    }

    @Test
    @Transactional
    public void getAllLookupsByValueNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where value does not contain DEFAULT_VALUE
        defaultLookupShouldNotBeFound("value.doesNotContain=" + DEFAULT_VALUE);

        // Get all the lookupList where value does not contain UPDATED_VALUE
        defaultLookupShouldBeFound("value.doesNotContain=" + UPDATED_VALUE);
    }


    @Test
    @Transactional
    public void getAllLookupsByCommentIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment equals to DEFAULT_COMMENT
        defaultLookupShouldBeFound("comment.equals=" + DEFAULT_COMMENT);

        // Get all the lookupList where comment equals to UPDATED_COMMENT
        defaultLookupShouldNotBeFound("comment.equals=" + UPDATED_COMMENT);
    }

    @Test
    @Transactional
    public void getAllLookupsByCommentIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment not equals to DEFAULT_COMMENT
        defaultLookupShouldNotBeFound("comment.notEquals=" + DEFAULT_COMMENT);

        // Get all the lookupList where comment not equals to UPDATED_COMMENT
        defaultLookupShouldBeFound("comment.notEquals=" + UPDATED_COMMENT);
    }

    @Test
    @Transactional
    public void getAllLookupsByCommentIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment in DEFAULT_COMMENT or UPDATED_COMMENT
        defaultLookupShouldBeFound("comment.in=" + DEFAULT_COMMENT + "," + UPDATED_COMMENT);

        // Get all the lookupList where comment equals to UPDATED_COMMENT
        defaultLookupShouldNotBeFound("comment.in=" + UPDATED_COMMENT);
    }

    @Test
    @Transactional
    public void getAllLookupsByCommentIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment is not null
        defaultLookupShouldBeFound("comment.specified=true");

        // Get all the lookupList where comment is null
        defaultLookupShouldNotBeFound("comment.specified=false");
    }
                @Test
    @Transactional
    public void getAllLookupsByCommentContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment contains DEFAULT_COMMENT
        defaultLookupShouldBeFound("comment.contains=" + DEFAULT_COMMENT);

        // Get all the lookupList where comment contains UPDATED_COMMENT
        defaultLookupShouldNotBeFound("comment.contains=" + UPDATED_COMMENT);
    }

    @Test
    @Transactional
    public void getAllLookupsByCommentNotContainsSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where comment does not contain DEFAULT_COMMENT
        defaultLookupShouldNotBeFound("comment.doesNotContain=" + DEFAULT_COMMENT);

        // Get all the lookupList where comment does not contain UPDATED_COMMENT
        defaultLookupShouldBeFound("comment.doesNotContain=" + UPDATED_COMMENT);
    }


    @Test
    @Transactional
    public void getAllLookupsByMultiSelectIsEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where multiSelect equals to DEFAULT_MULTI_SELECT
        defaultLookupShouldBeFound("multiSelect.equals=" + DEFAULT_MULTI_SELECT);

        // Get all the lookupList where multiSelect equals to UPDATED_MULTI_SELECT
        defaultLookupShouldNotBeFound("multiSelect.equals=" + UPDATED_MULTI_SELECT);
    }

    @Test
    @Transactional
    public void getAllLookupsByMultiSelectIsNotEqualToSomething() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where multiSelect not equals to DEFAULT_MULTI_SELECT
        defaultLookupShouldNotBeFound("multiSelect.notEquals=" + DEFAULT_MULTI_SELECT);

        // Get all the lookupList where multiSelect not equals to UPDATED_MULTI_SELECT
        defaultLookupShouldBeFound("multiSelect.notEquals=" + UPDATED_MULTI_SELECT);
    }

    @Test
    @Transactional
    public void getAllLookupsByMultiSelectIsInShouldWork() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where multiSelect in DEFAULT_MULTI_SELECT or UPDATED_MULTI_SELECT
        defaultLookupShouldBeFound("multiSelect.in=" + DEFAULT_MULTI_SELECT + "," + UPDATED_MULTI_SELECT);

        // Get all the lookupList where multiSelect equals to UPDATED_MULTI_SELECT
        defaultLookupShouldNotBeFound("multiSelect.in=" + UPDATED_MULTI_SELECT);
    }

    @Test
    @Transactional
    public void getAllLookupsByMultiSelectIsNullOrNotNull() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        // Get all the lookupList where multiSelect is not null
        defaultLookupShouldBeFound("multiSelect.specified=true");

        // Get all the lookupList where multiSelect is null
        defaultLookupShouldNotBeFound("multiSelect.specified=false");
    }
    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultLookupShouldBeFound(String filter) throws Exception {
        restLookupMockMvc.perform(get("/api/lookups?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(lookup.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].orderSeq").value(hasItem(DEFAULT_ORDER_SEQ)))
            .andExpect(jsonPath("$.[*].group").value(hasItem(DEFAULT_GROUP)))
            .andExpect(jsonPath("$.[*].meaning").value(hasItem(DEFAULT_MEANING)))
            .andExpect(jsonPath("$.[*].value").value(hasItem(DEFAULT_VALUE)))
            .andExpect(jsonPath("$.[*].comment").value(hasItem(DEFAULT_COMMENT)))
            .andExpect(jsonPath("$.[*].multiSelect").value(hasItem(DEFAULT_MULTI_SELECT.booleanValue())));

        // Check, that the count call also returns 1
        restLookupMockMvc.perform(get("/api/lookups/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultLookupShouldNotBeFound(String filter) throws Exception {
        restLookupMockMvc.perform(get("/api/lookups?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restLookupMockMvc.perform(get("/api/lookups/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingLookup() throws Exception {
        // Get the lookup
        restLookupMockMvc.perform(get("/api/lookups/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateLookup() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        int databaseSizeBeforeUpdate = lookupRepository.findAll().size();

        // Update the lookup
        Lookup updatedLookup = lookupRepository.findById(lookup.getId()).get();
        // Disconnect from session so that the updates on updatedLookup are not directly saved in db
        em.detach(updatedLookup);
        updatedLookup
            .name(UPDATED_NAME)
            .code(UPDATED_CODE)
            .orderSeq(UPDATED_ORDER_SEQ)
            .group(UPDATED_GROUP)
            .meaning(UPDATED_MEANING)
            .value(UPDATED_VALUE)
            .comment(UPDATED_COMMENT)
            .multiSelect(UPDATED_MULTI_SELECT);
        LookupDTO lookupDTO = lookupMapper.toDto(updatedLookup);

        restLookupMockMvc.perform(put("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isOk());

        // Validate the Lookup in the database
        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeUpdate);
        Lookup testLookup = lookupList.get(lookupList.size() - 1);
        assertThat(testLookup.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testLookup.getCode()).isEqualTo(UPDATED_CODE);
        assertThat(testLookup.getOrderSeq()).isEqualTo(UPDATED_ORDER_SEQ);
        assertThat(testLookup.getGroup()).isEqualTo(UPDATED_GROUP);
        assertThat(testLookup.getMeaning()).isEqualTo(UPDATED_MEANING);
        assertThat(testLookup.getValue()).isEqualTo(UPDATED_VALUE);
        assertThat(testLookup.getComment()).isEqualTo(UPDATED_COMMENT);
        assertThat(testLookup.isMultiSelect()).isEqualTo(UPDATED_MULTI_SELECT);
    }

    @Test
    @Transactional
    public void updateNonExistingLookup() throws Exception {
        int databaseSizeBeforeUpdate = lookupRepository.findAll().size();

        // Create the Lookup
        LookupDTO lookupDTO = lookupMapper.toDto(lookup);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restLookupMockMvc.perform(put("/api/lookups").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(lookupDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Lookup in the database
        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteLookup() throws Exception {
        // Initialize the database
        lookupRepository.saveAndFlush(lookup);

        int databaseSizeBeforeDelete = lookupRepository.findAll().size();

        // Delete the lookup
        restLookupMockMvc.perform(delete("/api/lookups/{id}", lookup.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<Lookup> lookupList = lookupRepository.findAll();
        assertThat(lookupList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
